package com.link2room.base.facade.impl;

import com.link2room.aeriabots.entity.Demo;
import com.link2room.base.facade.IDemoFacadeService;
import com.link2room.common.jpa.condition.ConditionDetail;
import com.link2room.common.jpa.condition.L2RCondition;
import com.link2room.common.jpa.criteria.CriteriaUtil;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.service.ICommonService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * Created by sss on 2016/8/11.
 */
@Component("demoFacadeService")
public class DemoFacadeServiceImpl implements IDemoFacadeService {
    @Resource
    private ICommonService commonService;
    @Override
    public void demo()throws Exception{
        Demo queryDemo=new Demo();
        queryDemo.setLhotelCode("222");
        HashMap<String,String> orderMap=new HashMap<String,String>();
        orderMap.put("id", CriteriaUtil.ASC);
        orderMap.put("num",CriteriaUtil.DESC);
        //相等条件查询
        QueryResult<Demo> res1 = commonService.findAllEQ(Demo.class, queryDemo);
        QueryResult<Demo> res2 = commonService.findAllEQ(Demo.class, queryDemo,0,2);
        QueryResult<Demo> res3 = commonService.findAllEQ(Demo.class, queryDemo,0,2,orderMap,null);
        QueryResult<Demo> res4 = commonService.findAllEQ(Demo.class, queryDemo,0,2,orderMap,new String[]{"hotelCode"});
        //复杂条件查询
        System.out.println(3333);
        L2RCondition l2RCondition=new L2RCondition();
        l2RCondition.setAndConditions(new ConditionDetail[]{new ConditionDetail(Demo.Demo_.num.toString(), CriteriaUtil.Operator.GT,3)});
        l2RCondition.setOrConditions(new ConditionDetail[]{new ConditionDetail(Demo.Demo_.rateId.toString(), CriteriaUtil.Operator.LIKE,"aa%"),new ConditionDetail(Demo.Demo_.rateId.toString(), CriteriaUtil.Operator.EQ,"ab6")});
        QueryResult<Demo> res5 = commonService.findAllByCondition(Demo.class, l2RCondition);
        System.out.println(3);
    }
}
